package com.demo.webservice.controller;

import com.alibaba.fastjson.JSON;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class WebServiceController {

    private static final Logger logger = LoggerFactory.getLogger(WebServiceController.class);

    @RequestMapping(value = "/webService")
    public String webService() throws Exception {
        JaxWsDynamicClientFactory dynamicClientFactory = JaxWsDynamicClientFactory.newInstance();
        Client client = dynamicClientFactory.createClient("http://localhost:8080/webservice/user?wsdl");
        Object[] objects = client.invoke("getName",1L);
        return JSON.toJSON(objects).toString();
    }
}
